home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows5 / xwinc100.zip / CONTRIB-.00 / CONTRIB- / contrib / examples / Xaw / xlist.c < prev    next >
C/C++ Source or Header  |  1991-01-22  |  3KB  |  104 lines

  1. /*
  2.  * This example demostrates how to use the Athena List widget.
  3.  * 
  4.  * November 30, 1989 - Chris D. Peterson
  5.  */
  6.  
  7. /*
  8.  * $XConsortium: xlist.c,v 1.5 91/01/22 19:24:50 gildea Exp $
  9.  *
  10.  * Copyright 1989 Massachusetts Institute of Technology
  11.  *
  12.  * Permission to use, copy, modify, distribute, and sell this software and its
  13.  * documentation for any purpose is hereby granted without fee, provided that
  14.  * the above copyright notice appear in all copies and that both that
  15.  * copyright notice and this permission notice appear in supporting
  16.  * documentation, and that the name of M.I.T. not be used in advertising or
  17.  * publicity pertaining to distribution of the software without specific,
  18.  * written prior permission.  M.I.T. makes no representations about the
  19.  * suitability of this software for any purpose.  It is provided "as is"
  20.  * without express or implied warranty.
  21.  *
  22.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  24.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  25.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  26.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  27.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  28.  */
  29.  
  30. #include <stdio.h>
  31.  
  32. #include <X11/Intrinsic.h>
  33. #include <X11/StringDefs.h>
  34.  
  35. #include <X11/Xaw/List.h>
  36.  
  37. #include <X11/Xaw/Cardinals.h>
  38.  
  39. static void Activate(), Syntax();
  40.  
  41. void 
  42. main(argc, argv)
  43. int argc;
  44. char **argv;
  45. {
  46.     Widget toplevel, list;
  47.     XtAppContext app_con;
  48.     Arg args[1];
  49.     static String items[] = {
  50.     "first list entry",
  51.     "second list entry",
  52.     "third list entry",
  53.     "fourth list entry",
  54.     NULL
  55.     };
  56.  
  57.     toplevel = XtAppInitialize(&app_con, "Xlist", NULL, ZERO,
  58.                    &argc, argv, NULL, NULL, ZERO);
  59.     if (argc != 1) 
  60.     Syntax(app_con, argv[0]);
  61.  
  62.     XtSetArg(args[0], XtNlist, items);
  63.     list= XtCreateManagedWidget( "list", listWidgetClass, toplevel, args, ONE);
  64.     XtAddCallback(list, XtNcallback, Activate, (XtPointer)NULL);
  65.     
  66.     XtRealizeWidget(toplevel);
  67.     XtAppMainLoop(app_con);
  68. }
  69.  
  70. /*    Function Name: Syntax
  71.  *    Description: Prints a the calling syntax for this function to stdout.
  72.  *    Arguments: app_con - the application context.
  73.  *                 call - the name of the application.
  74.  *    Returns: none - exits tho.
  75.  */
  76.  
  77. static void 
  78. Syntax(app_con, call)
  79. XtAppContext app_con;
  80. char *call;
  81. {
  82.     XtDestroyApplicationContext(app_con);
  83.     fprintf( stderr, "Usage: %s\n", call);
  84.     exit(1);
  85. }
  86.  
  87. /*    Function Name: Activate
  88.  *    Description: Called when a list item has been selected.
  89.  *    Arguments: w, closure - *** UNUSED ***.
  90.  *                 call_data - a pointer to the list info structure.
  91.  *    Returns: 
  92.  */
  93.  
  94. /* ARGSUSED */
  95. static void 
  96. Activate(w, closure, call_data)
  97. Widget w;
  98. XtPointer closure, call_data;
  99. {
  100.     XawListReturnStruct *item = (XawListReturnStruct*)call_data;
  101.     printf( "selected item %d; \"%s\"\n", item->list_index, item->string );
  102. }
  103.  
  104.